package com.ruoyi.courses.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.courses.domain.JwCourses;
import com.ruoyi.courses.service.IJwCoursesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 课程情况Controller
 * 
 * @author ruoyi
 * @date 2024-11-13
 */
@RestController
@RequestMapping("/courses/courses")
public class JwCoursesController extends BaseController
{
    @Autowired
    private IJwCoursesService jwCoursesService;

    /**
     * 查询课程情况列表
     */
    @PreAuthorize("@ss.hasPermi('courses:courses:list')")
    @GetMapping("/list")
    public TableDataInfo list(JwCourses jwCourses)
    {
        startPage();
        List<JwCourses> list = jwCoursesService.selectJwCoursesList(jwCourses);
        return getDataTable(list);
    }

    /**
     * 导出课程情况列表
     */
    @PreAuthorize("@ss.hasPermi('courses:courses:export')")
    @Log(title = "课程情况", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JwCourses jwCourses)
    {
        List<JwCourses> list = jwCoursesService.selectJwCoursesList(jwCourses);
        ExcelUtil<JwCourses> util = new ExcelUtil<JwCourses>(JwCourses.class);
        util.exportExcel(response, list, "课程情况数据");
    }

    /**
     * 获取课程情况详细信息
     */
    @PreAuthorize("@ss.hasPermi('courses:courses:query')")
    @GetMapping(value = "/{courseId}")
    public AjaxResult getInfo(@PathVariable("courseId") Long courseId)
    {
        return success(jwCoursesService.selectJwCoursesByCourseId(courseId));
    }

    /**
     * 新增课程情况
     */
    @PreAuthorize("@ss.hasPermi('courses:courses:add')")
    @Log(title = "课程情况", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JwCourses jwCourses)
    {
        SysUser user= SecurityUtils.getLoginUser().getUser();
        jwCourses.setDeptId(104L);
        jwCourses.setUserId(user.getUserId());
        return toAjax(jwCoursesService.insertJwCourses(jwCourses));
    }

    /**
     * 修改课程情况
     */
    @PreAuthorize("@ss.hasPermi('courses:courses:edit')")
    @Log(title = "课程情况", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JwCourses jwCourses)
    {
        return toAjax(jwCoursesService.updateJwCourses(jwCourses));
    }

    /**
     * 删除课程情况
     */
    @PreAuthorize("@ss.hasPermi('courses:courses:remove')")
    @Log(title = "课程情况", businessType = BusinessType.DELETE)
	@DeleteMapping("/{courseIds}")
    public AjaxResult remove(@PathVariable Long[] courseIds)
    {
        return toAjax(jwCoursesService.deleteJwCoursesByCourseIds(courseIds));
    }
}
